package com.disdr.bean;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class 驼峰式命名法 {

    /*public static void main(String[] args) throws IOException {
        String[] line = "buy_oper_manager,buy_tech_manager,quota_factor,group_coefficient,buy_shop_rate,buy_reward,shop_open_commission,group_open_commission".split(",");
        for(String str : line){
            System.out.println(驼峰式命名法.toCamelCase(str));
        }
    }*/

    public static void main(String[] args) {
        char c = 'A';
        System.out.println(c<'B');
        System.out.println(('A'-'a'));
        System.out.println(unCamelCase("userName"));
    }

    /**
     * 驼峰式命名法
     * 例如：user_name->userName
     */
    public static String toCamelCase(String s)
    {
        if (s == null)
        {
            return null;
        }
        if (s.indexOf('_') == -1)
        {
            return s;
        }
        s = s.toLowerCase();
        StringBuilder sb = new StringBuilder(s.length());
        boolean upperCase = false;
        for (int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);

            if (c == '_')
            {
                upperCase = true;
            }
            else if (upperCase)
            {
                sb.append(Character.toUpperCase(c));
                upperCase = false;
            }
            else
            {
                sb.append(c);
            }
        }
        return sb.toString();
    }
    /**
     * (反)驼峰式命名法
     * 例如：userName->user_name
     */
    public static String unCamelCase(String s){
        if (s == null){
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);

            if (c >= 'A' && c <= 'Z')
            {
                sb.append("_").append(c);
            }
            else
            {
                sb.append(c);
            }
        }
        return sb.toString().toLowerCase();
    }


}
